import config from 'config'
import httpFetch from 'share/httpFetch'
import errorMessage from "share/errorMessage";

export default {
  //判断里程补贴计价模式
  isLadder(){
    //9001代表单价模式 9002阶梯计价模式
    return  httpFetch.get(`${config.baseUrl}/api/pcfp/mode`)
  },

  //设置计价模式
  setMode(mode){
    return  httpFetch.get(`${config.baseUrl}/api/pcfp/mode/${mode}`)
  },

  //获取阶梯模式下规则数据
  getTieredRuleList(params){
    return httpFetch.post(`${config.baseUrl}/api/pcfp/mystep`,params)
  },

  //获取单价模式下规则数据
  getUnitRuleList(page,pageSize){
    return httpFetch.get(`${config.baseUrl}/api/private/car/for/public/?page=${page}&size=${pageSize}`)
  },

  //根据OID获取规则详情
  getTieredRuleDetail(id){
    return  httpFetch.get(`${config.baseUrl}/api/pcfp/step/rule/${id}`)
  },

  //单价模式下的新建规则
  addUnitRuleList(method,params){
    return httpFetch[method](`${config.baseUrl}/api/private/car/for/public`,params)
  },

  //阶梯模式下新建规则
  addTieredRuleList(params){
    return httpFetch.post(`${config.baseUrl}/api/pcfp/step/rule`,params)
  },

  //阶梯模式下修改规则
  changeTieredRule(params){
    return httpFetch.post(`${config.baseUrl}/api/pcfp/step/rule/update`,params)
  },

  //阶梯模式删除阶梯规则
  deleteTieredRuleList(id){
    return httpFetch.delete(`${config.baseUrl}/api/pcfp/step/rule/${id}`)
  },

  //单价模式下删除规则
  deleteUnitRuleList(id){
    return httpFetch.delete(`${config.baseUrl}/api/private/car/for/public/${id}`)
  },

  //阶梯模式添加阶梯
  addStep(params){
    return httpFetch.post(`${config.baseUrl}/api/pcfp/step`,params)
  },

  //获取是否修改规则状态
  getLadderModifyStatus(){
    return httpFetch.get(`${config.baseUrl}/api/pcfp/step/prompt`)
  },

  // 里程单价模式设置保存
  savePriceMileageSetting(params) {
    return new Promise(function (resolve, reject) {
      httpFetch.post(`${config.baseUrl}/api/function/profiles/setProfile`, params)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    });
  }
  ,
  //查询精度值
  queryDeviateValue() {
    return httpFetch.get(`${config.baseUrl}/api/public/car/unit/price`);
  },
  //设置精度值
  saveDeviateValue(unitPriceRange) {
    let params = {
      unitPriceRange, roleType: 'TENANT'
    }
    return httpFetch.post(`${config.baseUrl}/api/public/car/unit/price`, params);
  },

  // 费用途经点配置修改
  setEditable(params) {
    return httpFetch.get(`/api/public/car/unit/price/editable`, params)
      .catch(e => {
        errorMessage(e.response);
        throw e;
      });
  }
}
